import Xzes86Encode from "./search/search.js";

let path = "/api/v4/search_v3?t=general&q=node&correction=1&offset=0&limit=20&lc_idx=0&show_all_topics=0";
let cookie = document.cookie.match(/(?<=d_c0=)[^;]+/) || '"AGDcULaM9hGPTiUgGC5RhadnPXi6wa_TbfI=|1601383443"';
let href = location.href || "https://www.zhihu.com/search?type=content&q=node";
let Xzst81 = "";

let res = Xzes86Encode(href, path, Xzst81, cookie);

console.log(res);

// https://www.zhihu.com/search?type=content&q=node
//下面是请求代码

await JSpider.prototype.Ajax({
    urls:
        "https://www.zhihu.com/api/v4/search_v3?t=general&q=node&correction=1&offset=26&limit=20&lc_idx=26&show_all_topics=0&search_hash_id=1f49fc65e3a5c6f037313be41a33aee0&vertical_info=0%2C1%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C1",
    options: {
        headers: {
            "x-ab-param":
                "zw_sameq_sorce=999;tp_clubhyb=0;tsp_hotlist_ui=1;zr_intervene=0;se_club_ui=0;se_guess=0;li_car_meta=0;tp_contents=2;qap_question_author=0;pf_adjust=0;li_viptab_name=0;zr_slot_training=1;li_topics_search=0;li_catalog_card=1;se_topicfeed=0;se_colorfultab=1;se_ffzx_jushen1=0;li_sp_mqbk=0;li_edu_page=old;se_col_boost=0;tp_dingyue_video=0;zr_sim3=0;tp_discover=0;li_svip_cardshow=1;pf_profile2_tab=0;li_video_section=0;tp_topic_tab=0;li_ebook_gen_search=0;li_yxzl_new_style_a=1;pf_creator_card=1;li_vip_verti_search=0;pf_newguide_vertical=0;qap_question_visitor= 0;tp_topic_style=0;pf_fuceng=1;ls_video_commercial=0;li_panswer_topic=0;tp_zrec=0;pf_noti_entry_num=0;li_svip_tab_search=1;zr_expslotpaid=1;zr_rec_answer_cp=open;li_pl_xj=0;zr_slotpaidexp=1;li_paid_answer_exp=0;tp_topic_tab_new=0-0-0;top_test_4_liguangyi=1",
            "x-ab-pb": "CkDsCnILDwvXCigLAQuWC2cLQguaCy8LWAvtCkwLOQs4C7ULJwqXC7QKYAvkCoYLKgusCz4LmwtLC7kLEgslClILEiAAAAABAQAAAAAAAAABAAAAAAYAAAAAAAEAAAIAAAAFAA==",
            "x-api-version": "3.0.91",
            "x-app-za": "OS=Web",
            "x-requested-with": "fetch",
            "x-zse-83": "3_2.0",
            "x-zse-86": "1.0_a7YBgrHBc0FYkHFB1TxBgcuBnw2pb8N0hwx0S7906Lxp",
            "x-zst-81":
                "3_2.0aR_sn77yn6O92wOB8hPZnQr0EMYxc4f18wNBUgpTbT2xE_tq1_FZQ__064kYJvNMPqXTDLe1FCOm7LS1trxTA8OYLUL8iRnqB6kq24rZegO8nCSCzrxMQJxTD_tp6ukyK8FmDcpTdRtuQXtTlbXT2ccmHbS_VUPT16fq-AXmAgxL-cHT_Tf0kUQKF0ntHRX_h0nOrcO90vXmpUCOMULyjbx1JgcMJUXG8QLftbS_TgxK3UOGYGtLFuXf-wxpF0fzGve_6e9Y6w3MbBXLlqwfYJw9UBeXNqoLKq21HJxMNvNBjJLZyGeYjGXmjDexTC3fm_XGNvr8L92Xo_wL2GLmo6eBYvx9VGHCpbSqehwmEu3OCwLLf8LC",
        },
        referrer: "https://www.zhihu.com/search?type=content&q=node",
    },
    func: function (res, args) {
        let host = "https://www.zhihu.com";
        let end = args[0] >= 5 ? false : true;
        console.log(args);
        let index = res.search_action_info.lc_idx;
        let hash = res.search_action_info.search_hash_id;
        let path = `/api/v4/search_v3?t=general&q=node&correction=1&offset=${index}&limit=20&lc_idx=${index}&show_all_topics=0&search_hash_id=${hash}&vertical_info=0%2C1%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C1`;

        return [
            end,
            [
                host + path,
                {
                    headers: {
                        "x-zse-86": decode(
                            location.href,
                            path,
                            "3_2.0aR_sn77yn6O92wOB8hPZnQr0EMYxc4f18wNBUgpTbT2xE_tq1_FZQ__064kYJvNMPqXTDLe1FCOm7LS1trxTA8OYLUL8iRnqB6kq24rZegO8nCSCzrxMQJxTD_tp6ukyK8FmDcpTdRtuQXtTlbXT2ccmHbS_VUPT16fq-AXmAgxL-cHT_Tf0kUQKF0ntHRX_h0nOrcO90vXmpUCOMULyjbx1JgcMJUXG8QLftbS_TgxK3UOGYGtLFuXf-wxpF0fzGve_6e9Y6w3MbBXLlqwfYJw9UBeXNqoLKq21HJxMNvNBjJLZyGeYjGXmjDexTC3fm_XGNvr8L92Xo_wL2GLmo6eBYvx9VGHCpbSqehwmEu3OCwLLf8LC",
                            document.cookie.match(/(?<=d_c0=)[^;]+/)
                        ),
                    },
                },
            ],
        ];
    },
    type: "pipe",
});
